<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="medium" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="导入批次号" prop="batchNo">
        <el-input
          v-model="queryParams.batchNo"
          placeholder="请输入导入批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人员编码" prop="employeeCode">
        <el-input
          v-model="queryParams.employeeCode"
          placeholder="请输入人员编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="employeeName">
        <el-input
          v-model="queryParams.employeeName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="identityId">
        <el-input
          v-model="queryParams.identityId"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理状态" prop="processStatus">
        <el-select v-model="queryParams.processStatus" placeholder="请选择处理状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!--
      <el-form-item label="创建日期" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择创建日期">
        </el-date-picker>
      </el-form-item>
      -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['erecord:vehiclesImportDetail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['erecord:vehiclesImportDetail:edit']"
        >修改</el-button>
      </el-col>
      -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['erecord:vehiclesImportDetail:remove']"
        >删除</el-button>
      </el-col>
      <!--
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['erecord:vehiclesImportDetail:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="employeeImportDetailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column align="center" label="序号" width="55">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="id" align="center" prop="id" v-if="false" width="100"/>
      
      <el-table-column label="导入批次号" align="center" prop="batchNo" width="200"/>
      <el-table-column label="人员编码" align="center" prop="employeeCode" />
      <el-table-column label="姓名" align="center" prop="employeeName" />
      <el-table-column label="性别" align="center" prop="sexImport" />

      <el-table-column label="身份证号" align="center" prop="identityId" width="170"/>
      <el-table-column label="出生日期" align="center" prop="birthdate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务部门" align="center" prop="deptImport" width="120"/>
      <el-table-column label="服务类型" align="center" prop="serviceTypeImport" />
      <el-table-column label="岗位" align="center" prop="postImport" width="110"/>

      <el-table-column label="劳动合同" align="center" prop="laborContractUrl" >
        <template slot-scope="scope">
          <el-link v-if="scope.row.laborContract" style="font-size: 24px;" icon="el-icon-paperclip" @click="handleDownload(scope.row.laborContract)" />
        </template>
      </el-table-column>
      <el-table-column label="学历" align="center" prop="educationImport" />

      <el-table-column label="职称" align="center" prop="professionalTitle" />
      <el-table-column label="入职日期" align="center" prop="entryDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="离职日期" align="center" prop="quitDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.quitDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号码" align="center" prop="phone" width="120"/>
      <el-table-column label="社保" align="center" prop="socialInsuranceImport" />

      <el-table-column label="意外险" align="center" prop="accidentInsuranceImport" />

      <el-table-column label="身份证扫描件" align="center" prop="identityPictureUrl" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.identityPictureUrl" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="资格证书" align="center" prop="qualification" >
        <template slot-scope="scope">
          <span v-if="scope.row.qualification">
          <el-link v-for="(quUrl , index) in getUrls(scope.row.qualification)" v-bind:key="index" style="font-size: 24px;" icon="el-icon-paperclip" @click="handleDownload(quUrl)" />
          </span>
        </template>
      </el-table-column>
      <el-table-column label="员工状态" align="center" prop="employeeStatusImport" />

      <el-table-column label="处理状态" align="center" prop="processStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.processStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="处理信息" align="center" prop="processMsg" width="200"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy" />
      <!--
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['erecord:employeeImportDetail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['erecord:employeeImportDetail:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
      -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改人员导入明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="导入批次号" prop="batchNo">
          <el-input v-model="form.batchNo" placeholder="请输入导入批次号" />
        </el-form-item>
        <el-form-item label="人员编码" prop="employeeCode">
          <el-input v-model="form.employeeCode" placeholder="请输入人员编码" />
        </el-form-item>
        <el-form-item label="姓名" prop="employeeName">
          <el-input v-model="form.employeeName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别-import" prop="sexImport">
          <el-input v-model="form.sexImport" placeholder="请输入性别-import" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份证号" prop="identityId">
          <el-input v-model="form.identityId" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthdate">
          <el-date-picker clearable
            v-model="form.birthdate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="服务部门-import" prop="deptImport">
          <el-input v-model="form.deptImport" placeholder="请输入服务部门-import" />
        </el-form-item>
        <el-form-item label="服务部门" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入服务部门" />
        </el-form-item>
        <el-form-item label="岗位-import" prop="postImport">
          <el-input v-model="form.postImport" placeholder="请输入岗位-import" />
        </el-form-item>
        <el-form-item label="岗位" prop="postId">
          <el-input v-model="form.postId" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="劳动合同" prop="laborContract">
          <el-input v-model="form.laborContract" placeholder="请输入劳动合同" />
        </el-form-item>
        <el-form-item label="学历-import" prop="educationImport">
          <el-input v-model="form.educationImport" placeholder="请输入学历-import" />
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-input v-model="form.education" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="职称" prop="professionalTitle">
          <el-input v-model="form.professionalTitle" placeholder="请输入职称" />
        </el-form-item>
        <el-form-item label="入职日期" prop="entryDate">
          <el-date-picker clearable
            v-model="form.entryDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择入职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="离职日期" prop="quitDate">
          <el-date-picker clearable
            v-model="form.quitDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择离职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="手机号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="社保-import" prop="socialInsuranceImport">
          <el-input v-model="form.socialInsuranceImport" placeholder="请输入社保-import" />
        </el-form-item>
        <el-form-item label="社保" prop="socialInsurance">
          <el-input v-model="form.socialInsurance" placeholder="请输入社保" />
        </el-form-item>
        <el-form-item label="意外险-import" prop="accidentInsuranceImport">
          <el-input v-model="form.accidentInsuranceImport" placeholder="请输入意外险-import" />
        </el-form-item>
        <el-form-item label="意外险" prop="accidentInsurance">
          <el-input v-model="form.accidentInsurance" placeholder="请输入意外险" />
        </el-form-item>
        <el-form-item label="身份证扫描件" prop="identityPicture">
          <el-input v-model="form.identityPicture" placeholder="请输入身份证扫描件" />
        </el-form-item>
        <el-form-item label="资格证书" prop="qualification">
          <el-input v-model="form.qualification" placeholder="请输入资格证书" />
        </el-form-item>
        <el-form-item label="员工状态-import" prop="employeeStatusImport">
          <el-input v-model="form.employeeStatusImport" placeholder="请输入员工状态-import" />
        </el-form-item>
        <el-form-item label="员工状态" prop="employeeStatus">
          <el-radio-group v-model="form.employeeStatus">
            <el-radio
              v-for="dict in dict.type.employee_user_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="处理状态" prop="processStatus">
          <el-select v-model="form.processStatus" placeholder="请选择处理状态">
            <el-option
              v-for="dict in dict.type.sys_common_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处理信息" prop="processMsg">
          <el-input v-model="form.processMsg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEmployeeImportDetail, getEmployeeImportDetail, delEmployeeImportDetail, addEmployeeImportDetail, updateEmployeeImportDetail } from "@/api/erecord/employeeImportDetail";

export default {
  name: "EmployeeImportDetail",
  dicts: ['sys_common_status', 'employee_user_status', 'sys_user_sex'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人员导入明细表格数据
      employeeImportDetailList: [],
      // 弹出层标题
      title: "",
      // 是否新增
      isAdd : true,      
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchNo: undefined,
        employeeCode: undefined,
        employeeName: undefined,
        identityId: undefined,
        deptId: undefined,
        processStatus: undefined,
        createTime: undefined,
        orderByColumn: "update_time,employeeCode",
        isAsc: "desc,asc",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "创建日期不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    const batchNo = this.$route.params && this.$route.params.batchNo;
    //console.log("--------------------------  " , batchNo)
    if (batchNo) {
      this.queryParams.batchNo = batchNo;
      //this.form.batchNo = batchNo;
    }    
    this.getList();
  },
  methods: {
    /** 查询人员导入明细列表 */
    getList() {
      this.loading = true;
      listEmployeeImportDetail(this.queryParams).then(response => {
        this.employeeImportDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getUrls(val) {
      return val.split(',');
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        batchNo: undefined,
        employeeCode: undefined,
        employeeName: undefined,
        sexImport: undefined,
        sex: undefined,
        identityId: undefined,
        birthdate: undefined,
        deptImport: undefined,
        deptId: undefined,
        postImport: undefined,
        postId: undefined,
        laborContract: undefined,
        educationImport: undefined,
        education: undefined,
        professionalTitle: undefined,
        entryDate: undefined,
        quitDate: undefined,
        phone: undefined,
        socialInsuranceImport: undefined,
        socialInsurance: undefined,
        accidentInsuranceImport: undefined,
        accidentInsurance: undefined,
        identityPicture: undefined,
        qualification: undefined,
        employeeStatusImport: undefined,
        employeeStatus: undefined,
        avtar: undefined,
        remark: undefined,
        processStatus: undefined,
        processMsg: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        delFlag: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isAdd = true;
      this.title = "添加人员导入明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getEmployeeImportDetail(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.isAdd = false;
        this.title = "修改人员导入明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.isAdd == false) {
            updateEmployeeImportDetail(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addEmployeeImportDetail(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据').then(() => {
        this.loading = true;
        return delEmployeeImportDetail(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('erecord/employeeImportDetail/export', {
        ...this.queryParams
      }, `employeeImportDetail_${new Date().getTime()}.xlsx`)
    },
    /** 下载按钮操作 */
    handleDownload(ossId) {
      this.$download.oss(ossId)
    }
  }
};
</script>
